package com.xyz.entity.response;

import com.xyz.enums.ResponseEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * @author 夏永泽
 * @date 2022/3/29
 */
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class ResultResponse<T> {
    private String code;
    private String message;
    private T data;

    public static <T> ResultResponse<T> success(T data) {
        return new ResultResponse<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage(), data);
    }

    public static <T> ResultResponse<T> success(String message, T data) {
        return new ResultResponse<>(ResponseEnum.SUCCESS.getCode(), message, data);
    }

    public static ResultResponse<Object> success(String message) {
        return new ResultResponse<>(ResponseEnum.SUCCESS.getCode(), message, null);
    }

    public static ResultResponse<Object> success() {
        return new ResultResponse<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage(), null);
    }

    public static ResultResponse<Object> success(ResponseEnum responseEnum) {
        return new ResultResponse<>(responseEnum.getCode(), responseEnum.getMessage(), null);
    }

    public static ResultResponse<Object> failed(String message) {
        return new ResultResponse<>(ResponseEnum.FAILED.getCode(), message, null);
    }

    public static ResultResponse<Object> failed(String code, String message) {
        return new ResultResponse<>(code, message, null);
    }

    public static ResultResponse<Object> failed(ResponseEnum responseEnum) {
        return new ResultResponse<>(responseEnum.getCode(), responseEnum.getMessage(), null);
    }
}
